package com.yidi.system.service.imp;

import com.yidi.system.domain.SysRoleMenu;
import com.yidi.system.repository.SysRoleMenuRepository;
import com.yidi.system.service.SysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Xn
 * @ClassName: SysRoleMenuServiceImpl
 * @date ：2021-10-19 14:20
 * @describe ：
 */
@Service
public class SysRoleMenuServiceImpl implements SysRoleMenuService {

    @Autowired
    private SysRoleMenuRepository sysRoleMenuRepository;

    /**
     * 通过角色ID删除角色和菜单关联
     *
     * @param roleId 角色ID
     * @return 结果
     */
    @Override
    public void deleteRoleMenuByRoleId(Long roleId) {

        sysRoleMenuRepository.deleteRoleMenuByRoleId(roleId);
    }

    /**
     * 批量新增角色菜单信息
     *
     * @param roleMenuList 角色菜单列表
     * @return 结果
     */
    @Override
    public void batchRoleMenu(List<SysRoleMenu> roleMenuList) {
        for(SysRoleMenu rm : roleMenuList) {
            sysRoleMenuRepository.save(rm);
        }
    }

    @Override
    public void deleteRoleMenu(Long[] roleIds){
        for(Long roleId : roleIds){
            deleteRoleMenuByRoleId(roleId);
        }
    }
}
